package org.lavemylogic.friendsfinder;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import org.lavemylogic.friendsfinder.gps.CustomLocationManager;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;


public class MapActivity extends Activity implements OnMarkerClickListener, OnInfoWindowClickListener {

	private static GoogleMap _map;
	private List<LatLng> _friendList;
	
	private LatLng _currentLocation;
	
	public void setCurrentLocation(LatLng location) {
		_currentLocation = location;
	}
	
	public LatLng getCurrentLocation() {
		return _currentLocation;
	}
	
	public static GoogleMap getMap() throws Exception {
		if(_map == null) {
			throw new Exception("Map requested before onCreate!");
		}
		return _map;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_friends_on_map);

		initilizeMap();
		
		CustomLocationManager locManager = new CustomLocationManager(this);
		locManager.getCurrentLocation();
		
		_friendList = new ArrayList<LatLng>();
		
		for(LatLng friend : _friendList) {
			
			//GoogleMapController.setMarker();
		}
		
		_map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
              // Intent intent = new Intent(ShowFriendsOnMap.this,UserLocationsHistory.class);
              // startActivity(intent);
            }
        });
		
	}
	
	/**
     * function to load map. If map is not created it will create it for you
     * */
    private void initilizeMap() {
        if (_map == null) {
        	_map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
 
            // check if map is created successfully or not
            if (_map == null) {
                //throw
            }
        }
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.show_friends_on_map, menu);
		return true;
	}
	
	@Override
	public void onInfoWindowClick(Marker arg0) {
		
	}
	
	@Override
	public boolean onMarkerClick(Marker arg0) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
